package model.service;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import dom.domain.User;
import dom.domain.UserDAO;

public class queryUserService {
	private UserDAO userDao;
	private Map<String, String> map;
//	private User tempUser;
	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}


	public String queryUser(String userId) {
		map = new HashMap<String, String>();
		try {
			if (userId == null) {
				map.put("flag", "false");
				map.put("info","userId null");
				return JSONObject.fromObject(map).toString();
			}
			User tempUser = userDao.findById(userId);
			if (tempUser == null) {
				map.put("flag", "false");
				map.put("info", "user not found");
				return JSONObject.fromObject(map).toString();
			}
			else
			{
				map.put("flag","true");
				map.put("info","success");
				map.put("userInfo", JSONObject.fromObject(tempUser.toString()).toString());
//				map.put("")
			}
		} catch (JSONException e) {
			map.put("flag", "false");
			map.put("info", "data format error&&"+e.getMessage());
		}
		
		return JSONObject.fromObject(map).toString();
	}

}
